<template>
	<view class="index">
		<block v-for="(item,index) in commodity" :key="index" >
			<!-- <view class="commodity-item" @click="navigator" :data-id="item.goods_id"> -->
			<view class="commodity-item" @click="navigator(item.goods_id)">
				<image class="commodity-img" :src="item.goods_small_logo"></image>
				<!-- <text>{{item.goods_id}}</text> -->
				<view class="commodity-content">
					<text class="commodity-name">
						{{item.goods_name}}
					</text>
					<view class="">
						<text class="price">¥{{item.goods_price}}</text>
					</view>
					<text class="discount">{{discount}}折</text>
				</view>
			</view>
		</block>
		<!-- <Commodity></Commodity> -->
	</view>
</template>

<script>
	export default {
		props: ["commodity"],
		data() {
			return {
				discount: 0
			}
		},
		methods: {
			navigator(id) {
				this.$emit('goGoodsDetail', id)
				// this.$parent.goGoodsDetail(id.currentTarget.dataset.id)
				// console.log(44444,id.currentTarget.dataset.id)
			}
		},
		mounted() {
				this.discount = (Math.floor(Math.random() * (100 - 10 + 1)) + 10) / 10
		}


	}
</script>

<style scoped>
	.index {
		padding: 0 10rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
	}

	.commodity-item {
		width: 360rpx;
		padding-bottom: 20rpx;
		box-sizing: border-box;
	}

	.commodity-img {
		width: 100%;
		height: 375rpx;
		display: block;
		margin: auto;
	}

	.commodity-content {
		text-align: center;
	}

	.commodity-name {
		height: 80rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		color: #3333333;
		word-break: break-all;
		padding: 6rpx 20rpx;

	}

	.discount {
		font-size: 24rpx;
		border-radius: 4rpx;
		border: 1px solid #FF3333;
		padding: 2rpx 10rpx;
		color: #FF3333;
	}
</style>
